﻿using System;
using Is.Core;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Should.Fluent;


namespace Is.Test
{
    [TestClass]
    public class IsDateTimeExtensionsTest
    {
        [TestMethod]
        public void Test_IsEqual()
        {
            new DateTime(2011, 08, 31).Is().Equal(new DateTime(2011, 08, 31)).Should().Be.True();
            new DateTime(2011, 08, 31).Is().Equal(new DateTime(2011, 08, 30)).Should().Be.False();
            new DateTime(2011, 08, 31, 14, 09, 44, 555).Is().Equal(new DateTime(2011, 08, 31, 14, 09, 44, 555)).Should().Be.True();
            new DateTime(2011, 08, 31, 14, 09, 44, 555).Is().Equal(new DateTime(2011, 08, 31, 14, 09, 44, 556)).Should().Be.False();
            new DateTime(2011, 08, 31).Is().Equal(new DateTime(2011, 09, 30), DatePrecision.Year).Should().Be.True();
            new DateTime(2011, 08, 31).Is().Equal(new DateTime(2011, 09, 30)).Should().Be.False();
            new DateTime(2011, 08, 31).Is().Equal(new DateTime(2011, 08, 30), DatePrecision.Month).Should().Be.True();
            new DateTime(2011, 08, 31, 14, 09, 44, 555).Is().Equal(new DateTime(2011, 08, 31, 14, 09, 44, 556), DatePrecision.Second).Should().Be.True();
            new DateTime(2011, 08, 31, 14, 09, 44, 555).Is().Equal(new DateTime(2011, 08, 31, 15, 09, 44, 556), DatePrecision.Second).Should().Be.False();
            new DateTime(2011, 08, 31, 14, 09, 44, 555).Is().Equal(new DateTime(2011, 08, 31, 14, 09, 44, 556), DatePrecision.Date).Should().Be.True();
            new DateTime(2011, 08, 31, 14, 09, 44, 555).Is().Equal(new DateTime(2011, 08, 31, 14, 10, 45, 556)).Should().Be.False();
            new DateTime(2011, 08, 31, 14, 09, 44, 555).Is().Equal(new DateTime(2011, 08, 31, 14, 10, 45, 556), DatePrecision.Hour).Should().Be.True();
            new DateTime(2011, 08, 31, 14, 09, 44, 555).Is().Equal(new DateTime(2011, 08, 31, 14, 09, 45, 556)).Should().Be.False();
            new DateTime(2011, 08, 31, 14, 09, 44, 555).Is().Equal(new DateTime(2011, 08, 31, 14, 09, 45, 556), DatePrecision.Minute).Should().Be.True();

            new DateTime(2011, 08, 19).Is().Equal(new DateTime(2011, 08, 19).AddMinutes(5), TimeSpan.FromMinutes(6)).Should().Be.True();
            new DateTime(2011, 08, 19).Is().Equal(new DateTime(2011, 08, 19).AddMinutes(5), TimeSpan.FromMinutes(5)).Should().Be.True();
            new DateTime(2011, 08, 19).Is().Equal(new DateTime(2011, 08, 19).AddMinutes(5), TimeSpan.FromMinutes(4)).Should().Be.False();
        }

        [TestMethod]
        public void Test_IsToday()
        {
            new DateTime(2010, 08, 31).Is().Today().Should().Be.False();
            DateTime.Today.Is().Today().Should().Be.True();
            DateTime.Now.Is().Today().Should().Be.True();
        }

        [TestMethod]
        public void Test_IsGreaterThan()
        {
            DateTime today = DateTime.Today;
            DateTime tomorrow = DateTime.Today.AddDays(1);
            tomorrow.Is().GreaterThan(today).Should().Be.True();
            today.Is().GreaterThan(tomorrow).Should().Be.False();
            today.Is().GreaterThan(today).Should().Be.False();
        }

        [TestMethod]
        public void Test_IsGreaterThanOrEqualTo()
        {
            DateTime today = DateTime.Today;
            DateTime tomorrow = DateTime.Today.AddDays(1);
            tomorrow.Is().GreaterThanOrEqualTo(today).Should().Be.True();
            today.Is().GreaterThanOrEqualTo(tomorrow).Should().Be.False();
            today.Is().GreaterThanOrEqualTo(today).Should().Be.True();
        }

        [TestMethod]
        public void Test_IsLessThan()
        {
            DateTime today = DateTime.Today;
            DateTime tomorrow = DateTime.Today.AddDays(1);
            today.Is().LessThan(tomorrow).Should().Be.True();
            tomorrow.Is().LessThan(today).Should().Be.False();
        }

        [TestMethod]
        public void Test_IsLessThanOrEqualTo()
        {
            DateTime today = DateTime.Today;
            DateTime tomorrow = DateTime.Today.AddDays(1);
            tomorrow.Is().LessThanOrEqualTo(today).Should().Be.False();
            today.Is().LessThanOrEqualTo(tomorrow).Should().Be.True();
            today.Is().LessThanOrEqualTo(today).Should().Be.True();
        }
    }
}
